$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		update();
	}
});
function update() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/system/dlCompanyAlbum/update",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
$('#close').on('click', function () {
	layer.closeAll();
})
$('#successfulReview').on('click', function () {
	var firstdirectory = [];
	$("input:checkbox[name='companyAlbumId']:checked").each(function(i){
		firstdirectory[i] = $(this).val();
	});
	layer.open({
		id:1,
		type: 1,
		title:'确定审核成功吗',
		area : [ '200px', '100px' ],
		style: 'width:80%;height:auto;',
		btn:['确定','取消'],
		yes:function (index,layero) {
			//获取输入框里面的值
			$.ajax({
				cache : true,
				type : "POST",
				url : "/system/dlCompanyAlbum/updateStatus",
				data : {
					ids:firstdirectory.toString(),
					type: 1
				},
				async : false,
				error : function() {
					parent.layer.alert("操作失败");
					reLoad()
				},
				success : function(res) {
					parent.layer.alert(res.msg);
					parent.reLoad();
					var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
					parent.layer.close(index);
				}
			});
			layer.close(index);
			// 在这里提交数据
		},
		no:function (index,layero) {
			layer.close(index);
		}
	});

})


$('#auditFailure').on('click', function () {
	var firstdirectory = [];
	$("input:checkbox[name='companyAlbumId']:checked").each(function(i){
		firstdirectory[i] = $(this).val();
	});
	layer.open({
		id:1,
		type: 1,
		title:'请输入失败原因',
		area : [ '250px', '220px' ],
		style: 'width:80%;height:auto;',
		content: "<div style='display:flex;justify-content:center;' required lay-verify=\"required\"><textarea id='area' style='width:100%;height:135px;'></textarea></div>",
		btn:['确定','取消'],
		yes:function (index,layero) {
			//获取输入框里面的值
			var closeContent = top.$("#area").val() || $("#area").val();
			//把值存入redis中
			$.ajax({
				url: "/system/dlCompanyAlbum/auditFailureText",
				type:"post",
				data: {
					id: firstdirectory.toString(),
					auditFailureText: closeContent
				},
				success: function (res){
					//等待原因存入redis中在执行
					$.ajax({
						url: "/system/dlCompanyAlbum/updateStatus",
						data: {
							ids: firstdirectory.toString(),
							type: 2
						},
						type: "post",
						success: function (res){
							layer.msg(res.msg)
							parent.layer.msg("操作成功");
							parent.reLoad();
							var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
							parent.layer.close(index);
						}

					})
				}
			})


			layer.close(index);
			// 在这里提交数据
		},
		no:function (index,layero) {
			layer.close(index);
		}
	});


})
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			}
		},
		messages : {
			name : {
				required : icon + "请输入名字"
			}
		}
	})
}